package com.wyh;

import com.wyh.bean.Resume;
import com.wyh.repository.ResumeRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author wuyuhan
 * @date 2021/3/14 23:30
 */
@SpringBootApplication
public class MongoApplication {

    public static void main(String[] args) {
        ApplicationContext applicationContext = SpringApplication.run(MongoApplication.class,args);
        ResumeRepository resumeRepository = applicationContext.getBean(ResumeRepository.class);

        /**
         * 添加操作
         */
        Resume resume  = new Resume();
        resume.setName("ddd");
        resume.setBirthday(getBirthday());
        resume.setExpectSalary(20000);
        resume.setCity("beijing");
        resumeRepository.save(resume);

        /**
         * 查询操作
         */
        List<Resume> resumeList = resumeRepository.findAll();
        for(Resume result:resumeList){
            System.out.println(result);
        }

    }

    /**
     * 获得生日
     * @return
     */
    public static Date getBirthday(){
        Date date = null;
        String  dateStr = "yyyy-MM-dd hh:mm:ss";
        SimpleDateFormat simpleDateFormat  = new SimpleDateFormat(dateStr);
        try {
            date = simpleDateFormat.parse("1995-10-02 11:13:14");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
